#include "stdafx.h"
#include "RoseBed.h"

Interface_SplashScreen_Effect_Rose :: Interface_SplashScreen_Effect_Rose()
{
}

Interface_SplashScreen_Effect_Rose :: ~Interface_SplashScreen_Effect_Rose()
{
	mRoseImg.release();
	mHandler.reset(NULL);
	mHandler.release();
}

bool Interface_SplashScreen_Effect_Rose :: Initialize()
{
	std :: deque <Vector2> Points;
	float Height = APP_HEIGHT * 0.65f;
	
	for(float y = 0; y < 5; y++)
	{
		for(float x =  -APP_WIDTH * 0.5f; x < APP_WIDTH * 0.55f; x += 12.0f)
			Points.push_back(Vector2(x, Height));
		Height -= APP_HEIGHT * 0.01f * (7 - y);
	}
	mHandler = SmartPtr<ParticleSystem>(new ParticleSystem(Points.size()));
	for(size_t i = 0; i < Points.size(); i++)
		mHandler->Emit(1, Points[i]);

	mRoseImg = SmartPtr<hgeSprite>(g_pSplashScreen->RESOURCE()->GetSprite("SplashScreen_EffectRose"));
	mRoseImg->SetColor(ARGB(255, 0, 30, 50));
	return true;
}

void Interface_SplashScreen_Effect_Rose :: Update(const float & Interval)
{
	mHandler->Update(Interval);
}

void Interface_SplashScreen_Effect_Rose :: Render()
{
	g_pSplashScreen->HGESYSTEM()->System_SetState(HGE_TEXTUREFILTER , false);
	std :: deque <Graphic_Particle> * ReferenceList = mHandler->GetParticles();
	Graphic_Particle * Ref = NULL;
	float Scale = 1.0f;

	for(int i = static_cast<int>(ReferenceList->size()) - 1; i != -1; i--)
	{
		Ref = &ReferenceList->at(i);

		if(Scale > 0.8f && Ref->mPosition.y < APP_HEIGHT * 0.35f)
			Scale = 0.8f;
		else if(Scale > 0.7f && Ref->mPosition.y < APP_HEIGHT * 0.3f)
			Scale = 0.7f;

		mRoseImg->RenderEx(Ref->mPosition.x, Ref->mPosition.y, Ref->mBearing, 0.7741f * Scale, 0.7741f * Scale);
	}
	g_pSplashScreen->HGESYSTEM()->System_SetState(HGE_TEXTUREFILTER , true);
	Ref = NULL;
	ReferenceList = NULL;
}